home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / nfsrc21.zip / ISBIT.PRG < prev    next >
Text File  |  1991-08-15  |  3KB  |  89 lines

  1. /*
  2.  * File......: ISBIT.PRG
  3.  * Author....: Forest Belt, Computer Diagnostic Services, Inc.
  4.  * Date......: $Date:   15 Aug 1991 23:03:46  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/isbit.prv  $
  7.  * 
  8.  * This is an original work by Forest Belt and is placed in the
  9.  * public domain.
  10.  *
  11.  * Modification history:
  12.  * ---------------------
  13.  *
  14.  * $Log:   E:/nanfor/src/isbit.prv  $
  15.  * 
  16.  *    Rev 1.2   15 Aug 1991 23:03:46   GLENN
  17.  * Forest Belt proofread/edited/cleaned up doc
  18.  * 
  19.  *    Rev 1.1   14 Jun 1991 19:52:02   GLENN
  20.  * Minor edit to file header
  21.  * 
  22.  *    Rev 1.0   01 Apr 1991 01:01:32   GLENN
  23.  * Nanforum Toolkit
  24.  *
  25.  */
  26.  
  27.  
  28. /*  $DOC$
  29.  *  $FUNCNAME$
  30.  *     FT_ISBIT()
  31.  *  $CATEGORY$
  32.  *     String
  33.  *  $ONELINER$
  34.  *     Test the status of an individual bit
  35.  *  $SYNTAX$
  36.  *     FT_ISBIT( <cByte>, <nBitPos> ) -> lResult
  37.  *  $ARGUMENTS$
  38.  *     <cByte> is a character from CHR(0) to CHR(255)
  39.  *
  40.  *     <nBitPos> is a number from 0 to 7 conforming to standard right-to-left
  41.  *               bit-numbering convention and representing the position of the
  42.  *               bit within the byte.
  43.  *  $RETURNS$
  44.  *     .T. if designated bit is set (1), .F. if not set (0), NIL if
  45.  *      invalid parameters.
  46.  *  $DESCRIPTION$
  47.  *     Tests for status of any selected bit in the byte passed as a parameter.
  48.  *     Byte must be presented in CHR() form, as a literal constant, or as the
  49.  *     one-byte character result of an expression.
  50.  *
  51.  *     This function is presented to illustrate that bit-wise operations
  52.  *     are possible with Clipper code.  For greater speed, write .C or
  53.  *     .ASM versions and use the Clipper Extend system.
  54.  *  $EXAMPLES$
  55.  *     This code tests whether bit 3 is set in the byte represented by
  56.  *     CHR(107):
  57.  *
  58.  *      lBitflag := FT_ISBIT(CHR(107), 3)
  59.  *      ? lBitflag                  // result: .T.
  60.  *
  61.  *      This code tests whether bit 5 is set in the byte represented by ASCII
  62.  *      65 (letter 'A')
  63.  *
  64.  *      ? FT_ISBIT('A', 5)          // result: .F.
  65.  *
  66.  *     For a demonstration of Clipper bit manipulations, compile and
  67.  *     link the program BITTEST.PRG in the Nanforum Toolkit source code.
  68.  *  $SEEALSO$
  69.  *     FT_BITSET() FT_BITCLR()
  70.  *  $END$
  71.  */
  72.  
  73. FUNCTION FT_ISBIT(cInbyte,nBitPos)
  74.  
  75.   LOCAL lBitStat
  76.  
  77.   IF valtype(cInbyte) != "C" .or. valtype(nBitPos) != "N"  // parameter check
  78.      lBitStat := NIL
  79.   ELSE
  80.      if (nBitPos > 7) .or. (nBitPos < 0) .or. (nBitPos != int(nBitPos))
  81.         lBitStat := NIL
  82.      else
  83.         lBitStat := int(((asc(cInByte) * (2 ^ (7 - nBitPos))) % 256) / 128) == 1
  84.      endif
  85.   ENDIF
  86.  
  87. RETURN lBitStat
  88.  
  89.